<template>
  <el-col :span="24" style="height: 100%;">
    <el-tabs v-model="active" :stretch="true" style="height: 750px;overflow-y: auto" type="border-card"
             @tab-click="tabClick">
      <el-tab-pane label="医嘱" name="0">
        <orders-template ref="orderTemplateRef" :org-id="orgId" :template-master-id="templateMasterId"/>
      </el-tab-pane>
      <el-tab-pane label="处方" name="1" style="height: 100%;">
        <prescription-template-index ref="prescriptionTemplateIndexRef" :dept-id="deptId"
                                     :org-id="orgId" :template-master-id="templateMasterId"/>
      </el-tab-pane>
      <el-tab-pane label="检查" name="2">
        <exam-template-index ref="examTemplateIndexRef" :org-id="orgId" :template-master-id="templateMasterId"/>
      </el-tab-pane>
      <el-tab-pane label="检验" name="3">
        <lab-template-index ref="labTemplateIndexRef" :org-id="orgId" :template-master-id="templateMasterId"/>
      </el-tab-pane>
      <el-tab-pane label="处置治疗" name="4">
        <outp-treat-rec-template-index ref="outpTreatRecTemplateIndexRef" :org-id="orgId"
                                       :template-master-id="templateMasterId"/>
      </el-tab-pane>
    </el-tabs>
  </el-col>
</template>

<script lang="ts" setup>

import OrdersTemplate from "@/views/template/wholeSet/ordersTemplate.vue";
import ExamTemplateIndex from "@/views/template/wholeSet/examTemplate/examTemplateIndex.vue";
import LabTemplateIndex from "@/views/template/wholeSet/labTemplate/labTemplateIndex.vue";
import OutpTreatRecTemplateIndex from "@/views/template/wholeSet/outpTreatRecTemplate/outpTreatRecTemplateIndex.vue";
import PrescriptionTemplateIndex from "@/views/template/wholeSet/prescriptionTemplate/prescriptionTemplateIndex.vue";

const active = ref('0');
const props = defineProps({
  orgId: {
    type: String,
    default: 0
  },
  templateMasterId: {
    type: String,
    default: ""
  },
  deptId: {
    type: String,
    default: ""
  },
})

const orderTemplateRef = ref()
const examTemplateIndexRef = ref()
const labTemplateIndexRef = ref()
const outpTreatRecTemplateIndexRef = ref()
const prescriptionTemplateIndexRef = ref()
const currentTabName = ref('0')

function tabClick(obj: any) {
  const objThis = toRaw(obj)
  currentTabName.value = objThis.props.name
  if (objThis.props.name === '0') {
    nextTick(() => {
      orderTemplateRef.value.getList()
    })
  } else if (objThis.props.name === '1') {
    nextTick(() => {
      // prescriptionTemplateIndexRef.value.prescItemRefresh()
      prescriptionTemplateIndexRef.value.initInfo()
    })
  } else if (objThis.props.name === '2') {
    nextTick(() => {
      examTemplateIndexRef.value.examItemRefresh()
      examTemplateIndexRef.value.clearForm()
    })
  } else if (objThis.props.name === '3') {
    nextTick(() => {
      labTemplateIndexRef.value.labItemRefresh()
      labTemplateIndexRef.value.clearForm()
    })
  } else if (objThis.props.name === '4') {
    nextTick(() => {
      outpTreatRecTemplateIndexRef.value.getList()
    })
  }
}

/**
 * 弹出框关闭后，刷新列表
 * @param obj
 */
function clearFormAll() {
  if (currentTabName.value === '0') {
    nextTick(() => {
      orderTemplateRef.value.getList()
    })
  } else if (currentTabName.value === '1') {
    nextTick(() => {
      prescriptionTemplateIndexRef.value.initInfo()
    })
  } else if (currentTabName.value === '2') {
    nextTick(() => {
      examTemplateIndexRef.value.clearForm()
    })
  } else if (currentTabName.value === '3') {
    nextTick(() => {
      labTemplateIndexRef.value.clearForm()
    })
  } else if (currentTabName.value === '4') {
    nextTick(() => {
      outpTreatRecTemplateIndexRef.value.getList()
    })
  }
}

/**
 * 设置初始tab选中name
 */
function setActive() {
  active.value = "0"
}

defineExpose({
  setActive,
  clearFormAll
})
</script>


<style scoped>

:deep(.el-tabs--border-card ) {
  border: 1px solid #027687;
  margin-bottom: -20px;
  margin-top: -15px;
}

:deep(.el-tabs--border-card>.el-tabs__content) {
  padding: 0 !important;
}
</style>
